/* This program was created by ScottC on 9/5/2012 to receive serial signals from a computer to turn on/off 1-9 LEDs */void setup() {
// initialize the digital pins as an output.
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
// Turn the Serial Protocol ON
Serial.begin(9600);
}
void loop() {
byte byteRead;
/* check if data has been sent from the computer: */if (Serial.available()) {
/* read the most recent byte */
byteRead = Serial.read();
//You have to subtract '0' from the read Byte to convert from text to a number.
byteRead=byteRead-'0';
//Turn off all LEDSfor(int i=2; i<11; i++){
digitalWrite(i, LOW);
}
if(byteRead>0){
//Turn on the relevant LEDsfor(int i=1; i<(byteRead+1); i++){
digitalWrite(i+1, HIGH);
}
}
}
}
//Created by ScottC on send mouse coordinates to Arduinoimport processing.serial.*;
// Global variablesint new_sX, old_sX;
int nX, nY;
Serial myPort;
// Setup the Processing Canvasvoid setup(){
size( 800, 400 );
strokeWeight( 10 );
//Open the serial port for communication with the Arduino//Make sure the COM port is correct
myPort = new Serial(this, "COM6", 9600);
myPort.bufferUntil('\n');
}
// Draw the Window on the computer screenvoid draw(){
// Fill canvas grey
background( 100 );
// Set the stroke colour to white
stroke(255);
// Draw a circle at the mouse location
ellipse( nX, nY, 10, 10 );
//Draw Line from the top of the page to the bottom of the page//in line with the mouse.
line(nX,0,nX,height);
}
// Get the new mouse location and send it to the arduinovoid mouseMoved(){
nX = mouseX;
nY = mouseY;
//map the mouse x coordinates to the LEDs on the Arduino.
new_sX=(int)map(nX,0,800,0,10);
if(new_sX==old_sX){
//do nothing
} else {
//only send values to the Arduino when the new X coordinates are different.
old_sX = new_sX;
myPort.write(""+new_sX);
}
}
To connect ground to do this use a jumper wire to connect the ground pin on the arduino to the negative rail on the breadboard this allows all the LEDs to use the ground pin on the Arduino
Step2
To insert the resistors into the breadboard space the resistors out with one leg connected to the negative rail on the breadboard
Step 3
insert the LEDs The longest pin is the positive (+) and the shortest pin is the negative(-). If it is wired the wrong way it will not operation
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(100);
{digitalWrite(led2, HIGH);
delay(100);
digitalWrite(led2, LOW);
delay(100);}
{digitalWrite(led3, HIGH);
delay(100);
digitalWrite(led3, LOW);
delay(100);}// wait for a second
}
The lights are Blink sketch allowed us to create a number of LED animations/transitions. But it is only a matter of time before you opt for something more interactive. In this tutorial, we will make use of a photo resistor or light dependent resistor ( LDR) to create an exciting LED display.
Photo resistors are variable resistors which change resistance depending on the amount of light hitting the sensor. When you move your hand closer to the sensor, you tend to block an increasing amount of light, which increases the resistance of the photo resistor. As you move your hand away, the amount of light hitting the surface of the photo resistor increases, thus decreasing the resistance.
The change in the resistance of the LDR, will affect the voltage being read at one of the Arduino's Analog Input pins (A0). As resistance increases, the voltage drops.
V = IR
V = Voltage, I = Current, R = Resistance The voltage reading will be used to select which LED to turn on
We now have the power to control which LED we want to light up. This would look very nice with different coloured LEDs, but unfortunately I am stuck with the Yellow and Red ones from the Sparkfun Inventor's Kit.
source code :
//Define the analog pin the photo resistor is connected to (A0)int photoRPin = 0;
voidsetup() {
//initialise the LED Pins as OUTPUTSfor (int i=4; i<14; i++){
pinMode (i, OUTPUT);
}
}
voidloop(){
//Turn off all the LEDs before continuingfor (int i=4; i<14; i++){
digitalWrite(i, LOW);
}
/* Read the light level: Adjust the analog reading values ranging from 120 to 600 to span a range of 4 to 13. The analog reading of 120 is when there is maximum resistance, and the value of 600 is when there is minimum resistance. These analog readings may vary from photo resistor to photo resistor, and therefor you may need to adjust these values to suit your particular LDR. */int photoRead = map(analogRead(photoRPin), 120, 600, 4, 13);
/* Make sure the value of photoRead does not go beyond the values of 4 and 13 */int ledPin = constrain(photoRead, 4, 13);
/* Turn the LED on for a fraction of a second */digitalWrite(ledPin, HIGH);
delay(10);
digitalWrite(ledPin, LOW);
}
Creating
Andriod apps using MIT app inventor and connected the app with arduino
to make things work, I often get email stating something went missing
when they follow my tutorial, Here's a step by step tutorial on getting
started with creating MIT app inventor and control things with arduino
Technolgy
1. App Inventor: How to Make an Android App - The Basics
In this tutorial, I show you the basic concepts of Google App Inventor. Keep watching this series to learn many advanced features of the software. Remember, the things I go over in this video are essential to learn before building up your knowledge.
2.Getting Started with Arduino and Android
MIT app inventor and what are the requirements need to get started with this video series, anyone watching this video can make their own app and control a LED connected to arduino without any prior experience
Blinking an LED is the first thing we do when we getting started with electronics in this tutorial you will TURN ON and TURN OFF the LED, this is the Hello world example in this tutorial, you don't need any prior coding experience to make this application work. To test the app that created during this tutorial, you need an Android mobile or android supported devices to test your app. creating an app with MIT app inventor is very simple
#include<SoftwareSerial.h>Stringstate;// string to store incoming message from bluetoothvoidsetup(){Serial.begin(9600);// serial communication startedpinMode(13,OUTPUT);// LED connected to 13th pin}//-----------------------------------------------------------------------// voidloop(){while(Serial.available()){//Check if there is an available byte to readdelay(10);//Delay added to make thing stable charc=Serial.read();//Conduct a serial readstate+=c;//build the string- either "On" or "off"}if(state.length()>0){if(state=="on"){digitalWrite(13,HIGH);}elseif(state=="off"){digitalWrite(13,LOW);}state="";}//Reset the variable}
3.Multi Servo Motor Control with Arduino and Android app
Android app using MIT app inventor 2 , I created this app to control 6 servo motor using android and arduino, I have arduino uno, which has only 6 PWM pins that's the reason I created 6 servo control, If you want to control more than 6 you can use arduino Mega to do this
Need for Components
- Arduino Board
- HC-06 / 05 Bluetooth Module
- Servo Motor x4
- Wires and Breadboard
- Battery
- Android Device
You can find the Circuit Diagram for this project above. Connect your servo according to that, If possible power the Servos and arduino separately
Check the video below to know How to make mit app for controlling multiple stepper motor.
Arduino with voice commands using an Android Mobiles Before we make a voice activated home automatic system
More details Watching this vedio :
Thing that you'll need:
- 5 LED Indicators (the color of your choice) - Arduino UNO (a clone works fine) - HC-05 Serial Bluetooth Module - Solderless Breadboard - Jumper Cables
Bluetooth voice control for arduino source code
//Voice Activated Arduino (Bluetooth + Android)
//Feel free to modify it but remember to give credit
String voice;
int
led1 = 2, //Connect LED 1 To Pin #2
led2 = 3, //Connect LED 2 To Pin #3
led3 = 4, //Connect LED 3 To Pin #4
led4 = 5, //Connect LED 4 To Pin #5
led5 = 6; //Connect LED 5 To Pin #6
//--------------------------Call A Function-------------------------------//
6.How to make an Android phone controlled Arduino Robot
How
to make an app for controlling an robot by android app, you will be
using android phone as remote controller to control the robot. You need 2
gear motor with wheels A motor driver, you can use any of the motor
driver you want, I used L293D motor driver for this project. You also
need a battery and connecting wires, apart from that as usual a
Bluetooth and Arduino board is needed to complete this tutorial
#include<SoftwareSerial.h>SoftwareSerialBT(10,11);//TX, RX respetivelyStringreaddata;voidsetup(){BT.begin(9600);Serial.begin(9600);pinMode(3,OUTPUT);// connect to input 1 of l293dpinMode(4,OUTPUT);// connect to input 4 of l293dpinMode(5,OUTPUT);// connect to input 3 of l293dpinMode(6,OUTPUT);// connect to input 2 of l293d}//-----------------------------------------------------------------------// voidloop(){while(BT.available()){//Check if there is an available byte to readdelay(10);//Delay added to make thing stablecharc=BT.read();//Conduct a serial readreaddata+=c;//build the string- "forward", "reverse", "left" and "right"}if(readdata.length()>0){Serial.println(readdata);// print data to serial monitor// if data received as forward move robot forwardif(readdata=="forward"){digitalWrite(3,HIGH);digitalWrite(4,HIGH);digitalWrite(5,LOW);digitalWrite(6,LOW);delay(100);}// if data received as reverse move robot reverseelseif(readdata=="reverse"){digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,HIGH);digitalWrite(6,HIGH);delay(100);}// if data received as right turn robot to right direction.elseif(readdata=="right"){digitalWrite(3,HIGH);digitalWrite(4,LOW);digitalWrite(5,LOW);digitalWrite(6,LOW);delay(100);}// if data received as left turn robot to left directionelseif(readdata=="left"){digitalWrite(3,LOW);digitalWrite(4,HIGH);digitalWrite(5,LOW);digitalWrite(6,LOW);delay(100);}// if data received as stop, halt the robotelseif(readdata=="stop"){digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,LOW);digitalWrite(6,LOW);delay(100);}readdata="";}}//Reset the variable