Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Sunday, 22 February 2015

Wedo Thermostatic Fan

Now we've got a thermometer for the wedo, we can start doing some fun things!

The most obvious is a wedo thermostat which controls a fan. I quickly hooked up a couple of lego propeller blades to a medium PF motor (like the one in the standard wedo kit), and attached that to channel 2 on the wedo, and attached the wedo temperature sensor to channel 1.

Calibration is definitely a bit dodgey, but between sitting on my desk and grasping the sensor in my hand I got raw readings of between 0.6 and 0.7 (your sensor might report differently, so check for yourself).

make wedo device
make wedoConnector number
make wedoValue number

when start

..set wedoConnector to 1
..tell wedo to "readRaw"
..#say [wedoValue]
..set wedoValue to (wedoValue-0.6)*10
..if wedoValue <0 
...set wedoValue to 0
..if wedoValue >1 
...set wedoValue to 1
..#say [wedoValue]
..set wedoConnector to 2
..tell wedo to "setMotorSpeed"

..wait 0.5 secs

All we need to do is subtract 0.6 and multiply by 10 to get a value that should be between 0 and 1. Just in case it goes outside this range we check and clamp the value - otherwise the fan could start going backwards (which isn't going to warm the room up!).

Having built version 1.0, I realised it wasn't actually moving much air - everything was working as it was supposed to,  but the blades just weren't moving fast enough. On a normal project this would be a problem, but... it's LEGO! another minute rummaging through the parts bucket and I'd made a gearbox, which sped up the fan so that it was at least moving some air!

If you hold the sensor in your hand the fan speeds up (as it thinks it's hot), and if you cool it, it slows down! AWESOME!

For extra awesome you can piggyback the PF Servo on the back of the motor, connect a pointer to it, and it gives you an analog(ish) temperature readout!

No comments:

Post a Comment