This is my first successful robot using an Arduino and a ping sensor. The forward and reverse circuit is the same as the forward and reverse circuit I have posted on this blog and YouTube. The motor is a set of motors i bought from Radio Shack. The big silver transistor is a NPN 2N3055 that controls the stearig motor. The code is at the bottom.
And here is the code.
// by BirdshoBrad @ YouTube & Blogger
const int pingPin = 7;
int pin1 = 10;
int pin2 = 11;
int pin3 = 12;
void setup() {
Serial.begin(9600); // initialize serial communication:
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
}
void loop()
{
long duration;
// The PING is triggered by a HIGH pulse of 5 microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING, a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
Serial.println(duration);
delay(100);
if (duration > 2500) // the distance....about 8-10 inches
{digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, HIGH); //forward
}
else {
digitalWrite(pin3, LOW); // forward
delay(1500); // rest
digitalWrite(pin1, HIGH); // turnig transistor
digitalWrite(pin2, HIGH); // reverse
delay(3000);
digitalWrite(pin3, LOW);
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
delay(2000); //rest
}
}
Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts
Thursday, July 3, 2014
Wednesday, June 25, 2014
Parallax 2x16 3pin LCD
On my YouTube channel I was asked to send the code to this 3 pin LCD project to a fellow YouTuber. I tried to put the code in the comments, but it did not work so I started this blog to post codes and schematics.
On this project I used 2 normally open switches, 3 resisters (2 for pull downs for the buttons and one for the LED), 1 3 pin 2x16 Parallax LCD, and 1 Arduino UNO. The LED is connected to pin 11. The button for turning the LED on or off is connected to pin 9. TxPin is connected to pin 6, that is what controls the LCD. The button for the LCD back light is connected to pin 4. The only trouble I had with this is I couldn't figure out how to not delay the code for 2 seconds for turning the LCD on then off automatically. So if anyone has figured that out, that would be cool and remember to share the code.
// made by birdshotbrad@youtube.com
//for the 3 pin Parallax LCD ONLY
int led = 11;
int button = 9; //button to turn on or off LED
int val = 0;
int oldval = 0;
int state = 0;
int TxPin = 6; //lcd pin
int button2 = 4; //lcd backlight
int val2 = 0;
int oldval2 = 0;
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
void setup()
{
pinMode(led, OUTPUT);
pinMode(button, INPUT);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
pinMode(button2, INPUT);
}
void loop()
{
mySerial.begin(9600);
delay(100);
val = digitalRead(button);
val2 = digitalRead(button2);
if(val2 == HIGH){
mySerial.write(17); // backlight on
delay(2000);
mySerial.write(18); // backlight off
}
if((val == HIGH) && (oldval == LOW)){ //code to turn on or off LED and to show status of LED on lcd
state = 1 - state;
delay(5);
}
oldval = val;
if (state == 1) {
digitalWrite(led, HIGH);
mySerial.write(12);// refresh lcd
mySerial.print("LED ON");
mySerial.write(18);
}
else {
digitalWrite(led, LOW);
mySerial.write(12);
mySerial.print("LED OFF");
mySerial.write(18);
}
}
On this project I used 2 normally open switches, 3 resisters (2 for pull downs for the buttons and one for the LED), 1 3 pin 2x16 Parallax LCD, and 1 Arduino UNO. The LED is connected to pin 11. The button for turning the LED on or off is connected to pin 9. TxPin is connected to pin 6, that is what controls the LCD. The button for the LCD back light is connected to pin 4. The only trouble I had with this is I couldn't figure out how to not delay the code for 2 seconds for turning the LCD on then off automatically. So if anyone has figured that out, that would be cool and remember to share the code.
// made by birdshotbrad@youtube.com
//for the 3 pin Parallax LCD ONLY
int led = 11;
int button = 9; //button to turn on or off LED
int val = 0;
int oldval = 0;
int state = 0;
int TxPin = 6; //lcd pin
int button2 = 4; //lcd backlight
int val2 = 0;
int oldval2 = 0;
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
void setup()
{
pinMode(led, OUTPUT);
pinMode(button, INPUT);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
pinMode(button2, INPUT);
}
void loop()
{
mySerial.begin(9600);
delay(100);
val = digitalRead(button);
val2 = digitalRead(button2);
if(val2 == HIGH){
mySerial.write(17); // backlight on
delay(2000);
mySerial.write(18); // backlight off
}
if((val == HIGH) && (oldval == LOW)){ //code to turn on or off LED and to show status of LED on lcd
state = 1 - state;
delay(5);
}
oldval = val;
if (state == 1) {
digitalWrite(led, HIGH);
mySerial.write(12);// refresh lcd
mySerial.print("LED ON");
mySerial.write(18);
}
else {
digitalWrite(led, LOW);
mySerial.write(12);
mySerial.print("LED OFF");
mySerial.write(18);
}
}
This is me demonstrating the LCD above.
Subscribe to:
Posts (Atom)






