Using the same LED matrix as before, and swapping the Photo Resistor for a Flex (or Bend) sensor, and a slight modification to the code, I can now have a light show that can be controlled by "Bending".
I used my finger to bend the sensor, but I could have attached it to a plant, a tree or anything else that bends. The bending changes the resistance, and therefore the INPUT value at analog pin 0.
The parts required:
Arduino UNO
10 x Red LEDs
9 x 330 Ohm resistors for the LEDs
1 x 10K Ohm resistors for the flex sensor.
1 x Flex sensor
Wires and Breadboard to connect it all together
Most of the components needed for this project can be sourced from the Sparkfun Inventor's Kit
//Flex Sensor Pin (flexPin) //the analog pin the Flex Sensor is connected to int flexPin = 0;
void setup() { for (int i=4; i<14; i++){ pinMode(i, OUTPUT); //sets the led pins 4 to 13 to output } }
void loop(){ //Ensure to turn off ALL LEDs before continuing for (int i=4; i<14; i++){ digitalWrite(i, LOW); }
/* Read the flex Level Adjust the value 130 to 275 to span 4 to 13 The values 130 and 275 may need to be widened to suit the minimum and maximum flex levels being read by the Analog pin */ int flexReading = map(analogRead(flexPin), 130, 275, 4, 13);
// Make sure the value does not go beyond 4 or 13 int LEDnum = constrain(flexReading, 4, 13);
/*Call the blink function: this will turn the LED on for 10 milliseconds, and keep it off for only 1 millisecond. You can change the blink rate by changing these values, however, I want a quick response time when the flex sensor bends, hence the small values. LEDnum determines which LED gets turned on.*/ blink(LEDnum, 10,1); }
// The blink function - used to turn the LEDs on and off void blink(int LEDPin, int onTime, int offTime){ // Turn the LED on digitalWrite(LEDPin, HIGH);
// Delay so that you can see the LED go On. delay(onTime);
// Turn the LED Off digitalWrite(LEDPin, LOW);
// Increase this Delay if you want to see an actual blinking effect. delay(offTime); }
The flex sensor pins/legs are a bit fragile, so be careful when poking it into the breadboard.
Have you ever wondered if there was a way to store and retrieve data from a USB stick with an Arduino UNO? Most people choose SD cards to store their project data, but you may be surprised there IS a way! IC Station have a nice little module which allows you store and retrieve your Arduino (or other MCU) project data to a USB stick. I am not too sure why USB storage is not widely used in Arduino projects? These modules are not expensive, they have been around for quite a while, and are relatively simple to use. You do not need any libraries to get them to work, however, I must say that documentation for this module is not that easy to find. This site and this document proved to be very useful in my endevour to get this module working, and I hope my tutorial below will help you get started and bridge some of the information gaps. The...
Introduction Nextion is a programmable human machine interface (HMI) that can be customized and designed to simplify the interaction between you and your project. This Nextion Enhanced module (NX4827K043) with a resistive touch screen display, has some additional features not seen in previous traditional versions of the Nextion series. A built in real time clock (RTC) Accessible flash memory (32MB) GPIO functionality Faster clock speed Before you connect the Nextion Enhanced module to your project, you need to design your interface with the free Nextion Editor. The editor can be downloaded here. In this project, I will be designing a simple dynamic interface, which will allow me to interact with a stepper motor in two different ways. The first interface will let me control the direction and speed of the stepper motor through the use of a simple GUI. I will have left and right arrows for the direction, and up and down arrows for the speed. I will also map the Expansion board...
PART THREE If you happened to land on this page and missed PART ONE , and PART TWO , I would advise you go back and read those sections first. This is what you'll find in partone : Downloading and setting up the Android SDK Downloading the Processing IDE Setting up and preparing the Android device Running through a couple of Processing/Android sketches on an Andoid phone. This is what you will find in part two : Introducing Toasts (display messages) Looking out for BluetoothDevices using BroadcastReceivers Getting useful information from a discovered Bluetooth device Connecting to a Bluetooth Device An Arduino Bluetooth Sketch that can be used in this tutorial InputStream and OutputStream We will now borrow some code from the Android developers site to help us to establish communication between the Android phone and the Bluetooth shield on the Arduino. By this stage we have already scanned and discovered the bluetooth device and made a successful connection. We now need to create ...
Comments
Post a Comment