you/online and think of them as systems. • What are the inputs; what are the outputs? • Are the inputs and outputs digital (only on-off) or variable (have a range of values between fully on and fully off). • This is easier to consider for inputs, don’t worry about the details of outputs right now.
into a number and can turn a number into a voltage. • The code running on the device decides what happens to those numbers and how they are created. computer sensor sensor sensor actuator actuator actuator Digital: 0V or 5V —> 0 or 1 Analog: 0V to 5V —> 0 to 1023 Digital: 0 or 1 —> 0V or 5V Analog: 0 to 255 —> 0V to 5V (this is an oversimplification)
things like • make complex mappings from inputs to outputs • connect to another device with a wired connection like serial or I2C • make a wireless connection like wifi or Bluetooth
use an operating system to manage a bunch of programs. • Quick to start and easy to shut down (add power, take away power). • Usually much more limited than a full computer.
usually uses a Linux system. • Can handle multiple programs at the same time. • Takes longer to start up, and can be easy to corrupt data if you don’t follow proper shutdown procedures.
9600 ); } void loop() { int switchValue; switchValue = digitalRead( switchPin ); Serial.println( switchValue ); delay( 300 ); // slow down to make it easier to read }
changes in resistance or current. • But we can turn a changing current or resistance into a changing voltage by being clever. • Use a circuit called a voltage divider. Analog Sensor Circuits
it? Check with a multimeter. 2. If does, create a voltage divider. Decide if you want the object to be R1 or R2. 3. Choose a static resistor that gives you the values you are looking for. Generally you want a value that is halfway between the min and max resistances of your sensor. Analog Sensor Circuits
// Analog input pin that the potentiometer is attached const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue); // print the results to the serial monitor: Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); }
much current they need (how much they draw). • An actuator that needs too much current can harm your microcontroller. • Motors and a lot of LEDs will probably need more than your board can supply.
// Analog input pin that the potentiometer is attached const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue); // print the results to the serial monitor: Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); }
Bela is the single-board computer • Sits on a 2-layer fabric circuit board (FCB) • Hard-soft connection is stripped wire sewn onto conductive fabric pads
read — the same is true with code. • Start by reading and reusing code that is already written, then you will build up the experience to write your own sketches. • The example sketches that come with Arduino cover almost every basic interaction you’ll want.
and methods you have used so far. • If you are new to Arduino, just use one of the example sketches. • If you have a little Arduino experience, modify one of the examples. • If you are very experienced with Arduino, fully integrate the board into your project using hard-soft connections.