Im just learning how to work with the Arduino UNO an i´ve got a few Questions:
If I want to transfer any Signals from any Pc to the Arduino, i have to use digital inputs, right?
So the digital input pin changes between Low/High. So the Sequence between low and high transfers a certain Information, right?
Unfortunatly i do´nt understand how to "read" this information with the Arduino / how to program different sequences and their results.
For example: If pin 1 gets low, then high and then low (0 1 0 ) , a servo turns about 10 degree,
if the pin gets 0 1 0 1 0 1 , a servo turns about 20 degree etc.
If I want to transfer any Signals from any Pc to the Arduino, i have to use digital inputs, right?
That depends on how the signals are being output from the PC. What method did you have in mind ? It is more likely that the output from the PC will be via a serial link and you will need to read and parse the serial data.
Unfortunatly i do´nt understand how to "read" this information with the Arduino
The digitalRead() function will read the state of a pin, but see my comment about serial input.
how to program different sequences and their results.
Have you looked at and tried the examples in the IDE ? Forget input from the PC initially, just make some LEDs and a servo do something.
Thank you for your fast reply ! I want to control a little car via Arduino... first with wires and later via bluetooth). I want to control this car with x and y coordinates ( forwards, backwards and sidewards).
Arduinofail:
Thank you for your fast reply ! I want to control a little car via Arduino... first with wires and later via bluetooth). I want to control this car with x and y coordinates ( forwards, backwards and sidewards).
The easiest way to send complex control command from a PC to an Arduino would be "Serial".
On the PC you could use the serial monitor to send commands and see the response from the Arduino.
On the Arduino you could read the commands with "Serial.read()" to read control commands.
Bluetooth modules also work with serial connection, but in case of a bluetooth module you'd have to use a second serial port, i.e. an Arduino board with two or more serial ports (Leonardo, Mega or something) or you can emulate a second serial in software in some different pins.
So: Use serial to control your Arduino.
In a first step this doesn't require any additional cabling: The USB cable from the PC to the Arduino will do.
What program do you envisage using on the PC to do this ? From your reply it sounds like it will be a serial interface so you could use the Arduino Serial monitor initially but you will need something else if you are going to use one Arduino and Bluetooth.
For wired serial just use the Arduino Serial monitor. For a PC and a single Arduino via bluetooth I don't know. You could go PC to Arduino 1 via serial then Arduino 1 to Arduino 2 via bluetooth.
In any case you will need to write an Arduino program to receive, parse and act on the incoming serial data but first you need to get comfortable with the Arduino hardware and software environment. Look at, run and modify the examples that come with the IDE for instance.
Arduinofail:
Thank you very much! I don´t know, do you know any (easy) program to transfer that information?
Here is some simple code to control two servos
(untested code):
#include <Servo.h>
Servo servo1;
Servo servo2;
int servo1Pos, servo2Pos;
void setup()
{
Serial.begin(9600);
Serial.println("Good nicht and good luck!");
servo1.attach(8); // attaches the servo on pin 8 to the servo object
servo1.write(servo1Pos);
servo2.attach(9); // attaches the servo on pin 9 to the servo object
servo2.write(servo2Pos);
}
void loop()
{
if (Serial.available())
{
char servo=Serial.read();
if (servo=='1' || servo=='2')
{
delay(2);
char command=toupper(Serial.read());
if (command>='A' && command <='Z')
{
Serial.print("Set servo: ");
Serial.print(servo);
int value=40+(command-'A')*100/25; // control from 40...140 degrees
Serial.print(" to ");
Serial.println(value);
if (servo=='1') servo1.write(value);
else if (servo=='2') servo2.write(value);
}
}
}
}
You can send 2-character commands over serial to control two servos using the serial monitor:
First character:
1- servo1 control
2- servo2 control
Second character:
Letter 'A' to 'Z' control servo angle from 40 degrees to 140 degrees
So enter commands in the serial monitor like:
1G
2P
or something like that to control the servo angles.