Don't wanna be here? Send us removal request.
Text
Self-Balancing Robot
Self-Balance Robot is somewhat which balances itself and automatically corrects its position on disturbance.
youtube
How it works-
It will be prevented from falling by giving acceleration to the wheels according to its inclination from the vertical. If the bot gets tilts by an angle, than in the frame of the wheels, the centre of mass of the bot will experience a pseudo force which will apply a torque opposite to the direction of tilt.
Components-
1x Arduino UNO
1x HC-05 Bluetooth Module
1x MPU 6050
1x L293D
1x IC7805
1x Battery
2x 500 rpm MotorsAcrylic Sheet for building chassis
2x Motor clamps with screws
Some Large Screws
Jumper wires
Chassis-
Chassis is designed using Acrylic sheet.However,it can be designed using Wooden plank,plastic sheet etc. too.Sheet was cut to form 3 levels/floors.It's not mandatory,but is a good practice.No. of levels can be increased if desired.After markings,holes were made and chassis is assembled.
Connections-
A Fritzing file is shown below showing all connections.
MPU-6050 is used due to its DMP capability.It can procees the Raw Accelerometer & Gyro values to give the Yaw,Pitch,Roll.It greatly decreases the computation overhead.
HC-05 bluetooth module is used for communication between Bot and Android app.
L293d motor driver is used for controlling motor.
IC7805 voltage Regulator is used for providing 5V power supply to Arduino.However,using this IC is not necessary and battery can be directly plugged to Arduino.This is just used for Safety Purposes.
Software-
Libraries-
PID library by Brett Beauregard
Jeff Rowberg's I2CDev libraries for the MPU-6050
Luis Rodenas's sketch to calibrate the MPU-6050
digitalIOPerformance library for fast writing of pins
EEPROMex library by thijs for storing PID values in EEPROM memory
Complete code can be found at GITHUB repository
PID Tuning-
This is most important part of the process and the most difficult too!Control engineers set the PID parameters by experience.It's an art learnt through experience.There are various methods out there for PID tuning.
The best simple & easy method for PID tuning is-
Set I and D term to 0, and adjust P so that the robot starts to oscillate (move back and forth) about the balance position. P should be large enough for the robot to move but not too large otherwise the movement would not be smooth.
With P set, increase I so that the robot accelerates faster when off balance. With P and I properly tuned, the robot should be able to self-balance for at least a few seconds.
Finally, increase D so that the robot would move about its balanced position more gentle, and there shouldn’t be any significant overshoots.
The PID tuning may take considerable time depending on the requirement and adjustment.
APP-
The initial app used for testing is Arduino Bluetooth RC Car
PID tuning was done initially manually.A custom app has been developed for controlling robot.
Resources-
App , Electronics
References-
http://www.instructables.com/id/Simple-Self-balancing-Robot-w-Galileo-Gen-2/?ALLSTEPS
http://www.kerrywong.com/2012/03/21/a-self-balancing-robot-iii/
https://github.com/lukagabric/Franko/blob/master/Franko/Franko.ino
0 notes
Text
Leap Motion Enabled CSS 3D Game
Impressive things can be done using just HTML and CSS3.This game is yet another example of what can be achieved using CSS.
youtube
In this Game, I'm using
Leap Motion Device and LeapJs to steer the plane.
CSS 3D transforms to draw the city with everything in it.
Javascript to set the game in motion.
The buildings, plane and other 3d objects are HTML DOM elements transformed using CSS3.The day-night rotation is implemented with CSS transitions (Although, CSS Animations can be used for the same).
CSS is not meant to create serious 3D games as there are Performance issues(even after using GPU) , Browser Support Issues and its limitations in creating 3D graphics.
LEAP MOTION DEVICE
The Leap Motion system recognizes and tracks hands, fingers and finger-like tools. The device operates in an intimate proximity with high precision and tracking frame rate and reports discrete positions, gestures, and motion.This tracked frame data can be processed using LeapSDK. You can know more about Leap Motion SDK here
CSS3 Transforms
CSS transforms allow us to change the position of elements without disrupting the normal document flow. Transforms are implemented using a set of CSS properties that let us apply transformations like rotation, skewing, scaling and translation in both the plane and 3D space. CSS transition properties provide a way to control the animation speed for changing the properties over a given duration. We can also specify time intervals, durations and timing functions that follow a customizable acceleration curve. No Doubt,People have done awesome stuff. and this Game version too can be taken to whole another level by adding more details and interaction or perhaps using WebGL and Canvas.
Code for this version of the game prototype is available at GitHub.
WebGL vs CSS 3D Transforms
Basic CSS3 transforms | Desandro's Intro to CSS 3D
Leap Motion | LeapJs
Web Audio API
TRIDIV
HTML5 Canvas\
[EXAMPLES]
Keith Clark's
Michael Bromley's
Other's
0 notes
Video
tumblr
Air Paint App using Leap Motion as controller
1 note
·
View note
Text
AIR PAINTING USING LEAP MOTION CONTROLLER
The Leap Motion Controller tracks both hands and all 10 fingers with pinpoint precision and incredible speed.
In this project , we have made an air painting app with leap motion as a controller and leapjs as the coding language.
Using your finger as a painting brush, you can paint on the screen , choose colors from the palette,change colors , without touching anywhere.
Code:
For painting, we have used <canvas> element of html5 . This element acts the same way as a painting canvas in real.
<canvas id="scene" width="1000" height="600" style="border:1px solid #000000;">
For coding part , leap have their own js known as leapjs , and so we need to include leap.min.js file in our code.
<script src="../Leapmotion/leapjs-master/leap.min.js"> </script>
var canvas=document.getElementById('scene'); var ctx=canvas.getContext('2d'); var width=canvas.width, height=canvas.height; var red='#F00',green='#0F0',blue='#00F',white='#FFF',
black='#000',yellow='ffff00';
This is the canvas code on which we are drawing. We have used 6 colors for the palette ,including an eraser.
Palette -Different coloured strips so that we can choose among them
var imageObj = new Image(); imageObj.src = 'img/download.jpg'; imageObj.onload = function() { ctx.drawImage(imageObj, 950, 0,50,600); };
var imageObj2=new Image(); imageObj2.src='img/green.jpg'; imageObj2.onload=function(){ ctx.drawImage(imageObj2,900,0,50,600); };
var imageObj3=new Image(); imageObj3.src='img/black.jpg'; imageObj3.onload=function(){ ctx.drawImage(imageObj3,850,0,50,600); };
var imageObj4=new Image(); imageObj4.src='img/yellow.jpg'; imageObj4.onload=function(){ ctx.drawImage(imageObj4,800,0,50,600); };
var imageObj5=new Image(); imageObj5.src='img/white.jpg'; imageObj5.onload=function(){ ctx.drawImage(imageObj5,750,0,50,600); };
var imageObj6=new Image(); imageObj6.src='img/red.jpg'; imageObj6.onload=function(){ ctx.drawImage(imageObj6,700,0,50,600); };
Function setcolor for changing colors
var gcol = "red";
function setcolor(a) { gcol = a; }
Drawcircle is used for painting.It will be called multiple times in leaploop
function drawcircle(center,radius,gcol,fill) { ctx.beginPath(); ctx.arc(center[0],center[1],radius,0,2*Math.PI); ctx.closePath(); ctx.fillStyle=gcol; ctx.fill(); }
LeaptoScene function captures our finger tips coordinates , and converts it into the canvas's coordinates
var positions=new Array();
function leapToScene(position) { var x=position[0]; var y=position[1]; return [width/2+4*x,height-2*y]; }
Leap.loop
The loop() function sets up the Leap controller and WebSocket connection and invokes the specified callback function on a regular update interval.
Whole code needs to be written in Leap.loop so that the circles are drawn again and again and we get a paint effect.
We are recording the position of our finger in var finger and then
converting the leap tipPosition coordinates into our scene's coordinates.
We are controlling the brush stroke by specifying the radius accordingly.
If we move closer to the screen ,the pressure increases and stroke becomes thicker. If we move away from screen , the pressure decreases and stroke becomes thinner.
Leap.loop({enableGestures: true},function(frame){ var finger=frame.fingers[0]; positions[i,j]=leapToScene(finger.tipPosition); var radius=9/[(finger.touchDistance)*2]; if(radius>17) { radius=17; } if(finger.tipPosition[2]<80) { drawcircle(positions[i,j],radius,gcol); } if((frame.fingers.length > 0 && frame.fingers.length < 2)) { //stop motion if(flag==0&&positions[i,j]>[950]&&positions[i,j]<[990]) { a=setTimeout(function(){myfunc();},3000); } if(flag1==0&&positions[i,j]>[900]&&positions[i,j]<[949]) { b=setTimeout(function(){myfunc1();},3000); } if(flag2==0&&positions[i,j]>[850]&&positions[i,j]<[899]) {
c=setTimeout(function(){myfunc2();},3000); } if(flag3==0&&positions[i,j]>[800]&&positions[i,j]<[849]) {
d=setTimeout(function(){myfunc3();},3000); } if(flag4==0&&positions[i,j]>[750]&&positions[i,j]<[800]) {
e=setTimeout(function(){myfunc4();},3000); } if(flag5==0&&positions[i,j]>[700]&&positions[i,j]<[750]) {
f=setTimeout(function(){myfunc5();},3000); } } });
We are using setTimeout function for changing colors.As soon as we move our finger tip towards a color in palette for 3 seconds, the color changes according to the position we are in.
If we move back our fingers before 3 seconds , then color does not get changed.
As soon as a color is set, its flag is updated and all other flags are made 0.
function myfunc() { if(positions[i,j]>[950]&&positions[i,j]<[999]) {
flag++; } else{
flag=0; } if(flag==3) { flag1 = 0; flag2=0; flag3=0; flag4=0; flag5=0; setcolor("blue"); ctx.rect(950,0,49,600); ctx.fillStyle="blue"; ctx.fill(); } } function myfunc1() { if(positions[i,j]>[900]&&positions[i,j]<[949]) {
flag1++; } else {
flag1=0; } if(flag1==3) { flag = 0; flag2=0; flag3=0; flag4=0; flag5=0; setcolor("green"); ctx.rect(900,0,49,600); ctx.fillStyle="green"; ctx.fill(); } } function myfunc2() { if(positions[i,j]>[850]&&positions[i,j]<[899]) {
flag2++; } else{
flag2=0; } if(flag2==3) { flag1 = 0; flag=0; flag3=0; flag4=0; flag5=0; setcolor("black"); ctx.rect(850,0,49,600); ctx.fillStyle="black"; ctx.fill(); } } function myfunc3() { if(positions[i,j]>[800]&&positions[i,j]<[849]) {
flag3++; } else{
flag3=0; } if(flag3==3) { flag1 = 0; flag=0; flag2=0; flag4=0; flag5=0; setcolor("yellow"); ctx.rect(800,0,49,600); ctx.fillStyle="yellow"; ctx.fill(); } } function myfunc4() { if(positions[i,j]>[750]&&positions[i,j]<[799]) {
flag4++; } else{
flag4=0; } if(flag4==3) { flag1 = 0; flag=0; flag2=0; flag3=0; flag5=0; setcolor("white"); ctx.rect(750,0,49,600); ctx.fillStyle="white"; ctx.fill(); } } function myfunc5() { if(positions[i,j]>[700]&&positions[i,j]<[749]) {
flag5++;
}
else{
flag5=0; } if(flag5==3) { flag1 = 0; flag=0; flag2=0; flag3=0; flag4=0; setcolor("red"); ctx.rect(700,0,49,600); ctx.fillStyle="red"; ctx.fill(); } }

0 notes
Text
CHANGING BLINKING RATE OF LED W.R.T. DISTANCE BETWEEN RFDUINO AND DEVICE
In this project we have used RFduino.The rate ofblinking of led becomes faster as we comes nearer to the RFduino RFduino is connected to any low energy bluetooth device .The signal strength is calculated using void RFduinoBLE_onRSSI() function.
CODE
void RFduinoBLE_onRSSI(int rssi) { Serial.print(rssi); if (rssi <= -64 && rssi>=-566) { digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); delay(100); }
else if (rssi <= -25 && rssi>=-63) { digitalWrite(led, HIGH); delay(600); digitalWrite(led, LOW); delay(600); } else if (rssi <=10000 && rssi>=-24) { digitalWrite(led, HIGH); delay(2000); digitalWrite(led, LOW); delay(2000); }
}
0 notes
Video
tumblr
Blinking LED when RFduino is connected to a low energy Bluetooth device
0 notes
Text
Blinking LED wrt Signal Strength
In this project we have used RFduino.The rate ofblinking of led becomes faster as we comes nearer to the RFduino RFduino is connected to any low energy bluetooth device .The signal strength is calculated using void RFduinoBLE_onRSSI() function.
CODE
void RFduinoBLE_onRSSI(int rssi) { Serial.print(rssi); if (rssi <= -64 && rssi>=-566) { digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); delay(100); }
else if (rssi <= -25 && rssi>=-63) { digitalWrite(led, HIGH); delay(600); digitalWrite(led, LOW); delay(600); } else if (rssi <=10000 && rssi>=-24) { digitalWrite(led, HIGH); delay(2000); digitalWrite(led, LOW); delay(2000); }
}
0 notes
Text
RFDUINO
In this project we have automatically turn on the led whenever the person with iphone/ipad or any other device which offers low energy Bluetooth comes into the range of led.Whenever the device is connected or disconnected the led blinks 5 times .The LED is connected to RFduino which has inbuilt low energy bluetooth in it.Whenever the person with the device comes near to RFduino RFduino gives logic High to the pin to which the led is further connected and logic low whenever the device is not in the range of the RFduino .We can use any application of RFduino to connect the device to the RFduino
ARDUINO CODE
#include <RFduinoBLE.h>
int connection_led = 6;
void setup() {
pinMode(connection_led, OUTPUT);
RFduinoBLE.begin(); }
void loop() { RFduino_ULPDelay(INFINITE); }
void RFduinoBLE_onConnect() {for(int i=5;i>=0;i—)
{digitalWrite(connection_led, LOW); delay(200); digitalWrite(connection_led,HIGH); delay(200); } digitalWrite(connection_led,HIGH); }
void RFduinoBLE_onDisconnect() {for(int i=5;i>=0;i—)
{digitalWrite(connection_led, LOW); delay(200); digitalWrite(connection_led,HIGH); delay(200); digitalWrite(connection_led, LOW); }}
0 notes
Text
Controlling Windows Using Arduino
In this project we can perform some basic operations on windows using Arduino.
We have used the software called Gobetwino which can talk to Arduino using Serial Communication.The Arduino sends the command name to the serial port (there should be some command stored in Gobetwino with the same name).Assume that we have stored a command named NOTEPAD in the Gobetwino which opens a text file named sample.txt.Therefore to open the textfile named sample.txt we have to write the following code.This code opens sample.txt everytime the sketch is run in the arduino
void setup()
{
Serial.begin(9600); Serial.println("#S|NOTEPAD|[]#");
}
void loop()
{
}
In Gobetwino we have to create command NOTEPAD as shown below
Therefore everytime when this sketch is uploaded to the everytime txt file named Sample.txt will open up in the windows
0 notes
Text
360 DEGREE TURNTABLE
In this project we are making a 360 degree view of any product on the computer screen which can be controlled by the mouse.
We have made a case in which we have to put the rotating table.
The rotating table is connected to the DC motor which is further connected to the Arduino board.
The table rotates and then stop,at that moment a picture is clicked.In this way 50-60 photos are clicked.
For getting pure white background we have used photoshop.We have used its batching function to apply the same effect to all the photos.Then we have used css,javascript and html to create a 360 degree view on the web browser.
ARDUINO CODE
int motor1=5; int motor2=6;
void setup() {pinMode(motor1,OUTPUT); pinMode(motor2,OUTPUT); for(int i=100;i>=0;i—) { digitalWrite(motor1,HIGH); digitalWrite(motor2,LOW); delay(500); digitalWrite(motor1,LOW); digitalWrite(motor2,LOW); delay(1000);
} }
void loop() { }
CSS CODE
@charset “utf-8”; body, ul, li { margin: 0; padding: 0; } ul, li { list-style: none; } .menu { width: 600px; height: 455px; border: 6px solid #ccc; margin: 30px auto 0; overflow: hidden; } .menu ul { width: 100px; height: 100px; } .menu ul li img { display: block; width: 600px; height: 455px; }
JAVA SCRIPT CODE
$(function(){ var pic_X=$(‘.list’).offset().left; var pic_Y=$(‘.list’).offset().top; var pic_W=$(‘.list’).width()/2; var pic_H=$(‘.list’).height()/2; var center_X=pic_X+pic_W; var center_Y=pic_Y+pic_H; var movestop=pic_W/10; $(‘.list’).mousemove(function(event){ var mouse_X=event.pageX; var mouse_Y=event.pageY; if(mouse_X-center_X<=0){ moveImg(mouse_X,mouse_Y,’left’) }else{ moveImg(mouse_X,mouse_Y) } }); function moveImg(m_X,m_Y,dir){ var index=Math.ceil(Math.abs(m_X-center_X)/movestop); if(dir){ $(‘.list li’).eq(index).show().siblings().hide(); }else{ $(‘.list li’).eq(118-index).show().siblings().hide(); } } })
HTML CODE
<head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” /> <title>case rotation</title>
<link href=”css/style.css” rel=”stylesheet” type=”text/css” /> </head>
<body> <div id=”jquery-script-menu”> <div class=”jquery-script-center”>
</script> <script type=”text/javascript”
</script></div> <div class=”jquery-script-clear”></div> </div> </div> <h1 style=”margin-top:150px;” align=”center”;></h1> <div class=”menu”> <ul class=”list”> « <li><img alt=”Product 1” src=”1.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”2.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”3.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”4.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”5.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”6.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”7.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”8.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”9.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”10.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”11.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”12.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”13.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”14.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”15.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”16.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”17.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”18.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”19.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”20.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”21.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”22.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”23.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”24.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”25.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”26.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”27.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”28.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”29.jpg” width=”200” height=”200” /></li <li><img alt=”Product 1” src=”30.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”31.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”32.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”33.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”34.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”35.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”36.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”37.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”38.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”39.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”40.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”41.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”42.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”43.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”44.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”45.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”46.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”47.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”48.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”49.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”50.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”51.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”52.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”53.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”54.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”55.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”56.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”57.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”58.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”59.jpg” width=”200” height=”200” /></li> <li><img alt=”Product 1” src=”60.jpg” width=”200” height=”200” /></li>
</ul> </div>
<script type=”text/javascript” src=”js/script.js”></script> <script type=”text/javascript”>
var _gaq = _gaq || []; _gaq.push([‘_setAccount’, ‘UA-36251023-1’]); _gaq.push([‘_setDomainName’, ‘jqueryscript.net’]); _gaq.push([‘_trackPageview’]);
(function() { var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true; ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’; var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s); })();
</script>
</body> </html>






0 notes
Text
Changing sound W.R.T. tilting/inclination
We have made a box which can change its sound with respect to its tilting/extent. We have used a MMA7361 accelrometer, a micro sd card shield for arduino an arduino uno We are taking the readings from accelerometer process it in the arduino and then play the song according to the readings. We have usd sdmaster and tmrpcm libraries to access the wav format files stored in the memory card. sdmaster library helps in accessing the files and tmrpcm library helps in producing sounds using pwm of arduino pins . We have to first format the memory card and then store the wav files in it below is the code and circuit diagram
CODE TO READ FROM ACCELEROMETER
#include <AcceleroMMA7361.h>
AcceleroMMA7361 accelero; int x;
void setup() { Serial.begin(9600); accelero.begin(7, 6, 5, 4, A0, A1, A2); accelero.setARefVoltage(5); //sets the AREF voltage to 3.3V accelero.setSensitivity(LOW); //sets the sensitivity to +/-6G accelero.calibrate(); }
void loop() { x = accelero.getXAccel(); Serial.print("\nx: "); Serial.print(x); Serial.print("\tG*10^-2"); delay(1000); //make it readable }
CODE TO CHECK IF THE MEMORY CARD IS PRESENT IN THE SD CARD SHIELD OR NOT.IF YES THEN PLAY THE WAV FILE
#include <SD.h> // need to include the SD library #define SD_ChipSelectPin 8 //using digital pin 4 on arduino nano 328 #include <TMRpcm.h> #include<SPI.h>// also need to include this library... TMRpcm tmrpcm; // create an object for use in this sketch void setup() { Serial.begin(9600); tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized: Serial.print("111"); // don't do anything more if not } else{ Serial.print("222"); tmrpcm.play("3.wav"); //the sound file "1" will play each time the arduino powers up, or is reset } } void loop(){
}
FINAL CODE TO PLAY DIFFERENT AUDIO FILES W.R.T. TO THE EXTENT OF TILTING
#include <SD.h> // need to include the SD library #define SD_ChipSelectPin 8//using digital pin 4 #include <TMRpcm.h> // also need to include this library... #include <AcceleroMMA7361.h> #include<SPI.h>
AcceleroMMA7361 accelero; int x; int z2;
TMRpcm tmrpcm; void setup(){ Serial.begin(9600); accelero.begin(7, 6, 5, 4, A0, A1, A2); accelero.setARefVoltage(5); accelero.setSensitivity(LOW); accelero.calibrate(); tmrpcm.speakerPin = 9; if (!SD.begin(SD_ChipSelectPin)) { return; }
} void loop(){ digitalWrite(tmrpcm.speakerPin, LOW); x = accelero.getXAccel(); Serial.print("\nx: "); Serial.print(x);
if(x<20&&x>=-20) { tmrpcm.volume(1); tmrpcm.play("1.wav"); delay(1000); tmrpcm.volume(0); ;
} else if (x>-40&&x<=-19) { tmrpcm.volume(1); tmrpcm.play("2.wav"); delay(1000); tmrpcm.volume(0); } else if (x>=-60&&x<=-41){ tmrpcm.volume(1);
tmrpcm.play("3.wav"); delay(1000); tmrpcm.volume(0); } else if (x>=-300&&x<=-61){ tmrpcm.volume(1); tmrpcm.play("4.wav"); delay(1000); tmrpcm.volume(0); }
}
CIRCUIT DIAGRAM
0 notes
Photo


Telepresence Robot
Android Connected to arduino via USB on the go is used to control the robot remotely and view video feed in real time from a PC/Smartphone in the local area network.
CODE:
int incomingByte; // a variable to read incoming serial data into int A = 5; // motor- right int B = 6; int C = 10; // motor- left// int D = 11; int valuel=255; // pwm for motr left int valuer=255; // pwm for motor right void setup() { Serial.begin(9600); pinMode(A, OUTPUT); pinMode(B, OUTPUT); pinMode(C, OUTPUT); pinMode(D, OUTPUT); Serial.println("R=Fwd, C=Back , D=Left, G=Right, F=Stop, Q=left+, Z=left-, W= right+, X= right-"); } void loop() { if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'D') { digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) analogWrite(B, valuer); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(D, LOW); // turn the LED off by making the voltage LOW Serial.println("left"); Serial.println(valuer); delay(100); // wait for a second } if (incomingByte == 'G') { digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(B, LOW); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) analogWrite(D, valuel); // turn the LED off by making the voltage LOW Serial.println("right"); Serial.println(valuel); delay(100); // wait for a second } if (incomingByte == 'R') { digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(B, HIGH); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(D, HIGH); // turn the LED off by making the voltage LOW Serial.println("fwd"); delay(100); // wait for a second } if (incomingByte == 'C') { digitalWrite(A, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(B, LOW); // turn the LED off by making the voltage LOW digitalWrite(C, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(D, LOW); // turn the LED off by making the voltage LOW Serial.println("Back"); delay(100); // wait for a second } if (incomingByte == 'F') { digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(B, LOW); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(D, LOW); // turn the LED off by making the voltage LOW Serial.println("stop"); delay(100); // wait for a second } if (incomingByte == 'Q') { // LEFT MOTOR PLUS TURNS RIGHT valuel=valuel+20; delay(100); // wait for a second if (valuel>255) {valuel=255; } digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(B, LOW); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) analogWrite(D, valuel); // turn the LED off by making the voltage LOW Serial.println("right"); Serial.println("valueL"); Serial.println(valuel); delay(100); // wait for a second } if (incomingByte == 'Z') { // LEFT MOTOR MINUS TURNS RIGHT valuel=valuel-20; delay(100); // wait for a second if (valuel<0) {valuel=0; } digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(B, LOW); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) analogWrite(D, valuel); // turn the LED off by making the voltage LOW Serial.println("right"); Serial.println("valueL"); Serial.println(valuel); delay(100); // wait for a second } if (incomingByte == 'W') { // RIGHT MOTOR PLUS TURNS LEFT valuer=valuer+20; if (valuer>255) {valuer=255; } digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) analogWrite(B, valuer); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(D, LOW); // turn the LED off by making the voltage LOW Serial.println("left"); Serial.println("valueR"); Serial.println(valuer); delay(100); // wait for a second } if (incomingByte == 'X') { // RIGHT MOTOR MINUS TURNS LEFT valuer=valuer-20; if (valuer<0) {valuer=0; } digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) analogWrite(B, valuer); // turn the LED off by making the voltage LOW digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(D, LOW); // turn the LED off by making the voltage LOW Serial.println("left"); Serial.println("valueR"); Serial.println(valuer); delay(100); // wait for a second } } }
0 notes
Photo
LASER SHOW
CODE
void sendto (float x_target, float y_target); void do_pwm(); void hold(long length); void laser_on(); void laser_off(); void draw_letter(byte letter); float x_level; float y_level; float move_scale = 2.4; int laser_pin = 12; int x_speaker_pin = 5; int y_speaker_pin = 6; float exp_move = 2.7; //main value to adjust to change laser speed //controls exponential laser movement //lower values = faster drawing //drawing too fast will decrease quality //try setting it around 2.0 to 6 //this is the easiest variable to adjust to tweak quality vs. speed float min_move = 0.5; //if the laser gets this close to its target location - (on both axis) //it's considered close enough //larger values increase drawing speed (at expense of quality) //try setting it to about 0.5 float max_move = 30; //maximum allowed movement - helps keep things from moving too fast //when drawing long lines float laser_toggle_delay = 11; //extra delay in units of 20 us before toggling laser on / off - try 0 to 100 float line_delay = 8; //extra delay in units of 20 us at end of each line - try 0 to 100 float x_min_value = 5; //these set the minimum value for X and Y channels (on a scale of 0 to 255) float y_min_value = 5; //this helps compensate for non-linear response some speakers have right off "center" //these values must be below the corresponding max values //increasing these values decrease image size //try values of 0-30 - increase if you are having quality issues float x_max_value = 190; //these set the minimum voltage for X and Y channels (on a scale of 0 to 255) float y_max_value = 190; //this helps prevent the speaker from going outside its linear response range / distorting //these values must be about the corresponding min values //decreasing these values decrease image size //try values of about 190 - decrease if you are having quality issues //these values may also be manipulated to adjust the "aspect ratio" void setup() { pinMode(laser_pin, OUTPUT); pinMode(x_speaker_pin, OUTPUT); pinMode(y_speaker_pin, OUTPUT); //resets the default arduino PWM stuff to much higher speed setPwmFrequency(x_speaker_pin, 1); setPwmFrequency(y_speaker_pin, 1); } //basic routines //sendto (X,Y) - sends laser to X and Y coordinates - scale is always 0 to 255 (although actual resolution may be lower than this depending on above config values) //move (X,Y) - moves laser to X and Y coordinates -relative- to current position //move_scale = X - sets scaling - only used by "move" and "draw_letter" functions //scaling of 2.8 allows for 5 characters across //draw_letter("X") - draws single letter at single position (uppercase only - see routine for other supported characters) //draw_string("STRING", X, Y, COUNT) - draws a string at X,Y for COUNT times //marquee("HELLO WORLD", CHARACTERS) - draws a scrolling marquee CHARACTERS long - text is autoscaled to fit (4 to 7 characters long works best) //laser_off() - turns laser off //laser_on() - turns laser on //hold(time) - tells laser to hold current position for roughly 20 microseconds (useful if you need to force laser to "catch up" after moving a large distance) //put your laser control code here! void loop() { //run the default laser show demo demo(); } void demo() { marquee("THIS ARDUINO LASER SHOW USES AUDIO SPEAKERS FOR GALVOS!", 5); //star zoom in and out for (float loop = 0; loop < 25; loop ++) { move_scale = loop / 5; laser_off(); sendto (1,1); move (17,5); laser_on(); move (13,24); move (-30,-18); move (34,0); move (-30,18); move (13,-24); } for (float loop = 25; loop > 0; loop --) { move_scale = loop / 5; laser_off(); sendto (1,1); move (17,5); laser_on(); move (13,24); move (-30,-18); move (34,0); move (-30,18); move (13,-24); } //"speed test" move_scale = 1.8; float exp_move_holder; exp_move_holder = exp_move; for (exp_move = 8; exp_move >= 1; exp_move = exp_move - exp_move / 20) { draw_string("SPEED", 1, 1, 1); } for (exp_move = 1; exp_move <= 8; exp_move = exp_move + exp_move / 20) { draw_string("TEST", 1, 1, 1); } exp_move = exp_move_holder; //"pacman" demo - this code is very hacky... move_scale = 2.3; for (int x = 0; x < 10; x++) { draw_string("prrr", 1, 1, 2); draw_string("qsss", 1, 1, 2); } draw_string("prrg", 1, 1, 2); draw_string("qsg", 1, 1, 3); draw_string("pg", 1, 1 , 3); draw_string("q", 1, 1, 1); draw_string("g", move_scale * 16 / 1.3, 1, 1); draw_string("q", 1, 1, 1); draw_string("g", move_scale * 16 / 1.4, 1, 1); draw_string("ph", 1, 1, 3); for (int x = 0; x < 6; x++) { draw_string("p", 1, 1, 5); draw_string("q", 1, 1, 5); } marquee("LINK TO INSTRUCTABLE AT WWW.NOTHINGLABS.COM", 5); } void move (float x_movedir, float y_movedir) { x_movedir = x_movedir * move_scale; y_movedir = y_movedir * move_scale; sendto (x_level + x_movedir, y_level + y_movedir); } void sendto (float x_target, float y_target) { float x_move; float y_move; float temp_exp_move = exp_move; while (fabs(x_target - x_level) > min_move || fabs(y_target - y_level) > min_move) { x_move = (x_target - x_level) / temp_exp_move; y_move = (y_target - y_level) / temp_exp_move; while (fabs(x_move) > max_move || fabs(y_move) > max_move) { x_move = x_move *.5; y_move = y_move *.5; temp_exp_move = temp_exp_move * 1.5; } x_level = x_level + x_move; y_level = y_level + y_move; do_pwm(); } x_level = x_target; y_level = y_target; do_pwm(); hold(line_delay); } void laser_on() { hold(laser_toggle_delay); digitalWrite(laser_pin, HIGH); } void laser_off() { hold(laser_toggle_delay); digitalWrite(laser_pin, LOW); } void do_pwm() { //actual PWM code float x_adjust; float y_adjust; //adds any offset (but still maintains 0-255 range) / handles scaling x_adjust = x_min_value + (x_level * ((x_max_value - x_min_value) / 255)); y_adjust = y_min_value + ((y_level) * ((y_max_value - y_min_value) / 255)); if (x_adjust < 1) x_adjust = 1; if (y_adjust < 1) y_adjust = 1; if (x_adjust > x_max_value) x_adjust = x_max_value; if (y_adjust > y_max_value) y_adjust = y_max_value; analogWrite(y_speaker_pin, y_adjust); analogWrite(x_speaker_pin, x_adjust); } void hold(long length) { long loop2 = 0; length = length * 2; while (loop2 < length) { delay (1); //we'v messed with timers - so this is a bunch smaller than 1ms delay loop2 ++; } } //void draw_string(char text[], int x, int y, int count) void draw_string(String text, int x, int y, int count) { for (int loop = 0; loop < count; loop ++) { sendto (x,y); int i = 0; while (text.charAt(i) != '\0') { draw_letter(text.charAt(i)); i ++; } } } void marquee(String text, int characters) { float move_scale_holder; int i = 0; int loop = 0; move_scale_holder = move_scale; move_scale = 256 / (characters * 18); for (int x=0; x < characters + 2; x++) { text = String(" " + text + " "); } for (loop = 0; loop < (text.length() - 5); loop ++) { draw_string(text.substring(loop,loop + characters),move_scale * 9,1,1); draw_string(text.substring(loop,loop + characters),1,1,1); } move_scale = move_scale_holder; } void draw_letter(byte letter) { float temp_x_level = x_level; float temp_y_level = y_level; //all characters 16x16 (leave -plenty- of space on right side to prevent overlap with next character) //characters are drawn starting from upper left corner //"cursor" is automatically returned to top right corner laser_off(); switch (letter) { case 'A': move (0,16); laser_on(); move (7,-16); move (7,16); laser_off(); move (-10,-7); laser_on(); move (9,0); break; case 'B': laser_on(); move (0,16); move (11,-3); move (-7,-5); move (7,-5); move (-11,-3); break; case 'C': move (11,16); laser_on(); move (-11,-2); move (0,-12); move (11,-2); break; case 'D': laser_on(); move (0,16); move (9,-4); move (0,-8); move (-9,-4); break; case 'E': move (10,0); laser_on(); move (-10,0); move (0,14); move (10,2); laser_off(); move (-6,-10); laser_on(); move (-6,0); break; case 'F': move (10,0); laser_on(); move (-10,0); move (0,16); laser_off(); move (0,-8); laser_on(); move (5,0); break; case 'G': move (9,8); laser_on(); move (4,0); move (-1,8); move (-12,-2); move (0,-12); move (9,-2); break; case 'H': move (2,0); laser_on(); move (0,16); laser_off(); move (0,-8); laser_on(); move (9,0); laser_off(); move (0,8); laser_on(); move (0,-16); break; case 'I': move (5,0); laser_on(); move (0,16); break; case 'J': move (0,8); laser_on(); move (2,8); move (9,0); move (0,-16); break; case 'K': laser_on(); move (0,16); laser_off(); move (11,0); laser_on(); move (-9,-8); move (9,-8); break; case 'L': laser_on(); move (0,16); move (11,0); break; case 'M': move (0,16); laser_on(); move (0,-16); move (7,8); move (7,-8); move (0,16); break; case 'N': move (0,16); laser_on(); move (0,-16); move (11,16); move (0,-16); break; case 'O': laser_on(); move (11,0); move (0,16); move (-11,0); move (0,-16); break; case 'P': move (0,16); laser_on(); move (0,-16); move (11,4); move (-11,4); break; case 'Q': move (6,0); laser_on(); move (-6,8); move (6,8); move (6,-8); move (-6,-8); laser_off(); move (0,7); laser_on(); move (7,7); break; case 'R': move (0,16); laser_on(); move (0,-16); move (11,3); move (-11,5); move (11,10); break; case 'S': move (11,0); laser_on(); move (-11,4); move (11,6); move (-11,6); break; case 'T': laser_on(); move (13,0); laser_off(); move (-8,0); laser_on(); move (0,16); break; case 'U': laser_on(); move (2,16); move (9,0); move (2,-16); break; case 'V': laser_on(); move (5,16); move (5,-16); break; case 'W': laser_on(); move (3,16); move (4,-8); move (4,8); move (3,-16); break; case 'X': laser_on(); move (12,16); laser_off(); move (-12,0); laser_on(); move (12,-16); break; case 'Y': laser_on(); move (6,7); move (0,9); laser_off(); move (0,-9); laser_on(); move (6,-7); break; case 'Z': laser_on(); move (12,0); move (-12,16); move (12,0); break; case ' ': break; case '-': move (2,8); laser_on(); move (10,0); break; case '\'': move (8,0); laser_on(); move (0,4); break; case '!': move (5,0); //tweaked to make sure doesn't look like '?' laser_on(); move (-1,3); move (1,6); laser_off(); move (0,5); laser_on(); move (0,2); break; case '?': laser_on(); move (12,1); move (-6,6); move (0,2); laser_off(); move (0,5); laser_on(); move (0,2); break; case '.': move (5,14); laser_on(); move (0,2); move (0,-2); break; case '*': move (5,8); laser_on(); move (0,2); move (0,-2); break; case ':': move (5,2); laser_on(); move (0,3); laser_off(); move (0,5); laser_on(); move (0,3); break; case '/': move (0,16); laser_on(); move (12,-16); break; case '0': laser_on(); move (11,0); move (0,16); move (-11,0); move (0,-16); break; case '1': move (5,0); laser_on(); move (0,16); break; case '2': laser_on(); move (12,2); move (-12,14); move (12,0); break; case '3': laser_on(); move (12,3); move (-7,6); move (7,6); move (-12,3); break; case '4': laser_on(); move (0,7); move (12,0); laser_off(); move (0,-7); laser_on(); move (0,16); break; case '5': move (0,16); laser_on(); move (12,-5); move (0,-5); move (-12,0); move (0,-6); move (12,0); break; case '6': move (0,6); laser_on(); move (12,3); move (0,6); move (-12,1); move (0,-16); move (10,0); break; case '7': laser_on(); move (12,0); move (-10,16); break; case '8': move (0,2); laser_on(); move (12,12); move (-6, 2); move (-6,-2); move (12,-12); move (-6, -2); move (-6, 2); break; case '9': move (12,6); laser_on(); move (-12,-3); move (0,-3); move (12,4); move (0,12); break; //following characters are just for pacman demo //pacman open case 'p': move (6,0); laser_on(); move (6,2); move (-6,6); move (6,6); move (-6,2); move (-6,-8); move (6,-8); break; //pacman closed case 'q': move (6,0); laser_on(); move (6,7); move (-7,1); move (7,1); move (-6,7); move (-6,-8); move (6,-8); break; //pellet 1 case 'r': move (0,8); laser_on(); move (0,2); move (0,-2); break; //pellet 2 case 's': move (9,8); laser_on(); move (0,2); move (0,-2); break; //ghost case 'g': move (8,0); laser_on(); move (8,3); move (0,13); move (-4,-5); move (-4,5); move (-4,-5); move (-4,5); move (0,-13); move (8,-3); break; //ghost gets eaten case 'h': move (-7,8); laser_on(); move (3,3); move (-6,-6); move (3,3); move (3,-3); move (-6,6); break; } //return to bottom right corner of character "cell" - adds 2 spaces laser_off(); sendto (temp_x_level + (18 * move_scale) , temp_y_level); } /** * Divides a given PWM pin frequency by a divisor. * * The resulting frequency is equal to the base frequency divided by * the given divisor: * - Base frequencies: * o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz. * o The base frequency for pins 5 and 6 is 62500 Hz. * - Divisors: * o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64, * 256, and 1024. * o The divisors available on pins 3 and 11 are: 1, 8, 32, 64, * 128, 256, and 1024. * * PWM frequencies are tied together in pairs of pins. If one in a * pair is changed, the other is also changed to match: * - Pins 5 and 6 are paired. * - Pins 9 and 10 are paired. * - Pins 3 and 11 are paired. * * Note that this function will have side effects on anything else * that uses timers: * - Changes on pins 3, 5, 6, or 11 may cause the delay() and * millis() functions to stop working. Other timing-related * functions may also be affected. * - Changes on pins 9 or 10 will cause the Servo library to function * incorrectly. * * Thanks to macegr of the Arduino forums for his documentation of the * PWM frequency divisors. His post can be viewed at: * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4 */ void setPwmFrequency(int pin, int divisor) { byte mode; if(pin == 5 || pin == 6 || pin == 9 || pin == 10) { switch(divisor) { case 1: mode = 0x01; break; case 8: mode = 0x02; break; case 64: mode = 0x03; break; case 256: mode = 0x04; break; case 1024: mode = 0x05; break; default: return; } if(pin == 5 || pin == 6) { TCCR0B = TCCR0B & 0b11111000 | mode; } else { TCCR1B = TCCR1B & 0b11111000 | mode; } } else if(pin == 3 || pin == 11) { switch(divisor) { case 1: mode = 0x01; break; case 8: mode = 0x02; break; case 32: mode = 0x03; break; case 64: mode = 0x04; break; case 128: mode = 0x05; break; case 256: mode = 0x06; break; case 1024: mode = 0x7; break; default: return; } TCCR2B = TCCR2B & 0b11111000 | mode; } }
0 notes
Photo

Toy Crane Hacking
This toy was interfaced with arduino board and was controlled remotely from a PC
CODE
int motor1 = 10; int motor2 = 9; int motor3 = 12; int incomingByte; void setup() {Serial.begin(9600); pinMode(motor1, OUTPUT); pinMode(motor2, OUTPUT); pinMode(motor3, OUTPUT); } void loop() { if (Serial.available() > 0){ incomingByte=Serial.read(); if(incomingByte=='W') { digitalWrite(motor1, HIGH); digitalWrite(motor2, LOW); digitalWrite(motor3,LOW); delay(100); } else if(incomingByte=='S') { digitalWrite(motor1, LOW); digitalWrite(motor2, HIGH); digitalWrite(motor3,HIGH); delay(100); } else if(incomingByte=='A') { digitalWrite(motor1, HIGH); digitalWrite(motor2, LOW); digitalWrite(motor3,HIGH); delay(100); } else if(incomingByte=='D') { digitalWrite(motor1, HIGH); digitalWrite(motor2, HIGH); digitalWrite(motor3,LOW); delay(100); } else if(incomingByte=='P') { digitalWrite(motor1, HIGH); digitalWrite(motor2, HIGH); digitalWrite(motor3,HIGH); delay(100); } } }
0 notes
Photo


RC Land Rover
Wireless Robot control with RF Receiver-Transmitter pair.
Code:
Reciever
#include <VirtualWire.h> int A = 8; int B = 9; int C = 10; int D = 11; void setup() { vw_set_ptt_inverted(true); // Required for DR3100 vw_set_rx_pin(12); vw_setup(4000); // Bits per sec vw_rx_start(); // Start the receiver PLL running pinMode(A, OUTPUT); pinMode(B, OUTPUT); pinMode(C, OUTPUT); pinMode(D, OUTPUT); } void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; if (vw_get_message(buf, &buflen)) // Non-blocking { if(buf[0]=='R'){ digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(B, HIGH); // turn the LED off by making the voltage LOW delay(100); digitalWrite(C, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(D, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second } if(buf[0]=='L'){ digitalWrite(A, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(B, LOW); // turn the LED off by making the voltage LOW delay(100); digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(D, HIGH); // turn the LED off by making the voltage LOW delay(100); // wait for a second } if(buf[0]=='F'){ digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(B, HIGH); // turn the LED off by making the voltage LOW delay(100); digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(D, HIGH); // turn the LED off by making the voltage LOW delay(100); // wait for a second } if(buf[0]=='B'){ digitalWrite(A, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(B, LOW); // turn the LED off by making the voltage LOW delay(100); digitalWrite(C, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(D, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second } if(buf[0]=='S'){ digitalWrite(A, LOW); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(B, LOW); // turn the LED off by making the voltage LOW delay(100); digitalWrite(C, LOW); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(D, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second } } }
Transmitter:
#include <VirtualWire.h> char *controller; const int ledPin = 13; // the pin that the LED is attached to int incomingByte; // a variable to read incoming serial data into void setup() { pinMode(13,OUTPUT); vw_set_ptt_inverted(true); // vw_set_tx_pin(12); vw_setup(4000);// speed of data transfer Kbps // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); } void loop() { // see if there's incoming serial data: if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'S') { controller="S" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone delay(200); } if (incomingByte == 'F') { controller="F" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone delay(200); } if (incomingByte == 'B') { controller="B" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone delay(200); } if (incomingByte == 'L') { controller="L" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone delay(200); } if (incomingByte == 'R') { controller="R" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone delay(200); } } }
0 notes
Photo

AC Remote Hacking
LEDs controlled from AC remote
CODE
#include <IRremote.h> int IR_Recv = 0; //IR Receiver Pin 3 int g_ledPin = 9; //green LED pin 5 int r_ledPin = 8; //red LED pin 9 int ledPins[] = {8, 9}; //array with all the LED's pins int ledStates[] ={0, 0}; //this means the LED's states at first is 0 = LOW int i=0; //LED index for the arrays IRrecv irrecv(IR_Recv); decode_results results; int ledState = LOW; // ledState to turn the LED on or off long previousMillis = 0; // stores last time LED was updated long interval = 100000; // interval at which to blink (milliseconds) void setup(){ Serial.begin(9600); //starts serial communication irrecv.enableIRIn(); // Starts the receiver pinMode(g_ledPin, OUTPUT); // sets the digital pin as output pinMode(r_ledPin, OUTPUT); // sets the digital pin as output } void loop(){ if (irrecv.decode(&results)){ long int decCode = results.value; Serial.println(decCode); if(results.value>=1686110244 ){ digitalWrite(r_ledPin,HIGH); digitalWrite(g_ledPin,LOW); } else {digitalWrite(r_ledPin,LOW); digitalWrite(g_ledPin,HIGH); } irrecv.resume(); // Receives the next value from the button you press } //this if statment makes the LED blink if it's selected and off }
0 notes