Arduino Projects: Difference between revisions

 
(13 intermediate revisions by the same user not shown)
Line 91:
 
= Versatile Kitchen Timer =
 
{{notice|This code can be re-wired using capacitative touch sensor.}}
 
[[File:Kitchen Versatile Timer.jpg|thumb|right|Kitchen Versatile Timer]]
 
<pre style="width: 75%; height: 10pc; overflow-y: scroll;">
//This code is written by Amandeep Singh
Line 465 ⟶ 468:
= Bluetooth Controlled RC Car =
Source: [http://www.instructables.com/id/Arduino-Bluetooth-RC-Car-Android-Controlled/ instructables.com], [http://www.instructables.com/id/Control-DC-and-stepper-motors-with-L298N-Dual-Moto/ instructables.com]
 
[[File:Arduino Bluetooth RC Car bb.png|thumb|right|Arduino Bluetooth RC Car]]
 
<pre style="width: 75%; height: 10pc; overflow-y: scroll;">const int motor1Pin1 = 10;
const int motor1Pin2 = 11;
const int enablem1Pin3 = 12;
const int motor2Pin1 = 6;
const int motor2Pin2 = 5;
const int enablem2Pin3led = 38;
const int buzzer = 12;
int i = 0;
 
byte serialA;
 
 
void setup() {
Serial.begin(9600);
 
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enablem1Pin3, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enablem2Pin3led, OUTPUT);
pinMode(buzzer, OUTPUT);
}
 
void alarm()
{
for (int i=0; i<2; i++) //alarm will ring for 2 seconds once triggered
{
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(100);
}
}
 
 
void loop() {
Line 499 ⟶ 519:
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, HIGH);
break;
Line 509 ⟶ 527:
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, LOW);
break;
Line 519 ⟶ 535:
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(enablem1Pin3, LOW);
digitalWrite(enablem2Pin3, HIGH);
break;
Line 529 ⟶ 543:
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, HIGH);
break;
 
// forward right
case 'I':
Line 540 ⟶ 551:
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, HIGH);
break;
 
// backward left
Line 551 ⟶ 559:
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, HIGH);
break;
Line 561 ⟶ 567:
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, HIGH);
break;
Line 571 ⟶ 575:
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
digitalWrite(enablem1Pin3, HIGH);
digitalWrite(enablem2Pin3, HIGH);
break;
Line 581 ⟶ 583:
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
digitalWrite(enablem1Pin3, LOW)break;
digitalWrite(enablem2Pin3, LOW); }
} case 'W':
digitalWrite(led, HIGH);
break;
case 'w':
digitalWrite(led, LOW);
break;
case 'V':
alarm();
break;
}
}
</pre>
 
==Bluetooth RC Car with Speed Control==
{{notice|Need to implement the Speed control using the enable pins on L298N instead of the Input Pins}}
[[File:Arduino Bluetooth RC Car bb.png|thumb|right|Arduino Bluetooth RC Car]]
Line 771 ⟶ 785:
= Obstacle Avoiding Robot =
 
{{UC}}
<pre style="width: 75%; height: 10pc; overflow-y: scroll;">
 
= Bluetooth Controlled RGB LED Strip =
</pre>
Source: [https://www.arduino.cc/en/Tutorial/ReadASCIIString arduino.cc],
<br />
 
Download the AndroidunoBt App from: [https://play.google.com/store/apps/details?id=com.embarcadero.AndroidunoBt&hl=en play.google.com]
= Bluetooth Controlled RGB LED Strip =
 
Source: [https://www.arduino.cc/en/Tutorial/ReadASCIIString arduino.cc], [https://play.google.com/store/apps/details?id=com.embarcadero.AndroidunoBt&hl=en play.google.com]
[[File:Bluetooth Controlled RGB LED Strip.jpg|thumb|right]]
 
*Reading a serial ASCII-encoded string.
Line 966 ⟶ 981:
<br />
 
=Running Lights with Speed Control using Potentiometer=
 
http://arduino.stackexchange.com/questions/19605/running-light-without-delay-and-a-potentiometer
Source: [http://arduino.stackexchange.com/questions/19605/running-light-without-delay-and-a-potentiometer stackexchange.com]
 
[[File:Running Lights with Speed Control using Potentiometer.jpg|thumb|right]]
 
<pre style="width: 75%; height: 10pc; overflow-y: scroll;">
// Sketch re: http://arduino.stackexchange.com/questions/19605/running-light-without-delay-and-a-potentiometer
// Set constants for pins with LEDs
enum { led1 = 13, led2 = 12, led3 = 11, led4 = 10, led5 = 9, led6 = 8, led7 = 7, led8 = 6, led9 = 5, led10 = 4};
 
// Make an array with the LED pin numbers
byte ledPins[] = { led1, led2, led3, led4, led5, led6, led7, led8, led9, led10 };
 
// # of entries in ledPins:
enum { numLeds = sizeof(ledPins) / sizeof ledPins[0]};
 
//count to track which LEDs are HIGH and which are LOW
int count = numLeds-1; // Will roll over to 0
 
// To store last time LED was updated
unsigned long previousMillis = 0;
 
void setup() {
// initialize digital pin outputs
for (byte i=0; i<numLeds; ++i)
pinMode(ledPins[i], OUTPUT);
 
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
 
// loop() runs over and over again forever:
void loop() {
unsigned long currentMillis = millis();
// read input on analog pin 0:
int deli = analogRead(A0);
float voltage = deli * (5.0 / 1023.0);
 
// Print out the value and corresponding voltage you read:
// Serial.println("Value: %d and Voltage: %f", pause, voltage);
Serial.print("Value: ");
Serial.println(deli);
Serial.print("Volts: ");
Serial.println(voltage);
 
if (currentMillis - previousMillis >= deli) {
// Save the last time we blinked the LED
previousMillis = currentMillis;
 
// Turn off current LED, turn on next one
digitalWrite(ledPins[count], LOW);
count = (count+1) % numLeds;
digitalWrite(ledPins[count], HIGH);
}
}
</pre>
 
= LED Matrix Clock =
https://123led.wordpress.com/mini-led-clock/
{{UC}}
 
= RF 433 MHz Module =
 
Source: [https://randomnerdtutorials.com/rf-433mhz-transmitter-receiver-module-with-arduino/ randomnerdtutorials.com]
 
*Download the Library file:
https://lastminuteengineers.com/libraries/RadioHead-1.84.zip
 
*Connect the circuit as below:
Arduino Tx Module
5v VCC
GND GND
12 Data
 
Arduino Rx Module
5v VCC
GND GND
11 Data
 
*Transmitter Side Code
<pre>
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
 
RH_ASK driver;
 
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
 
void loop()
{
const char *msg = "Hello World!";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);
}
</pre>
 
 
*Receiver Side Code
<pre>
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
 
RH_ASK driver;
 
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
 
void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
</pre>
 
= Motor Shield =
 
Source: [https://lastminuteengineers.com/l293d-motor-driver-shield-arduino-tutorial/ lastminuteengineers.com]
 
*Single DC power supply for both Arduino and motors:
Plug Voltage < 12V into the DC jack on the Arduino or the 2-pin EXT_PWR block on the shield.
Jumper ON
*(Recommended) Arduino via USB and motors via DC power supply:
Arduino plug in the USB cable.
Then connect the motor supply to the EXT_PWR block on the shield.
Jumper OFF
 
*Arduino Jack and motors via DC power supply:
Plug in the supply for the Arduino into the DC jack.
Connect the motor supply to the EXT_PWR block.
Jumper OFF
 
Warning:
DO NOT supply power to the EXT_PWR input when jumper is in place.
It may damage the motor shield and also your Arduino!
 
The shield offers below features:
The shield comes with a pulldown resistor array to keep motors switched off during power-up.
The on-board LED indicates the motor power supply is Okay. If it is not lit, the motors will not run.
The RESET is nothing but Arduino’s reset button. It just brought up top for convenience.
 
<br />
<br />