IoT simulation which will record the movement and orientation of phone and give feedback
IoT simulation which will record the movement and orientation of phone and give feedback in Tinker Cad with code
Tinker Cad Circuit Design:
Component Requirements:
1) Arduino Uno R3
2) Micro Servo
3) Potentiometer 250 Kilo Ohms
Code for the Circuit:
#include <Servo.h>
#include <SoftwareSerial.h>
int pos = 0;
int sensorValue = 0;
int i = 0;
Servo servo_9;
void setup(){
servo_9.attach(9);
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(A0);
pos = map(sensorValue,0,1023,0,180);
for (i = 0; i <= pos; i++) {
if(i == 90){
Serial.println("Landscape");
} else if( i == 180 || i == 0){
Serial.println("Portrait");
}
servo_9.write(i);
delay(15);
}
for (i= pos; i >= 0; i --) {
if(i == 90){
Serial.println("Landscape");
}
servo_9.write(i);
delay(15);
}
}
Comments
Post a Comment