18 comments

1

Using programming to affect physical objects in real life is so much fun! Even a simple project can bring a lot of satisfaction and end up useful.

Here's some comments/questions about your code:

Why don't you stop the motors inside the open/closeBlinds() functions? A function should be a complete idea that does what its name implies. What you currently have could be dangerous - if you forget to add a motor [motorB] = 0 statement after calling the function, the motor will just keep running, wasting some power in the best case scenario, damaging itself or other objects in the worst.

To overcome the problem that @taxation_is_slavery mentioned (the blinds opening and closing rapidly when the light intensity is right around 50, going slightly above and below regularly) you could set a higher threshold for when to close the blinds and a lower for when to open them. Somewhere in the range of 45-55 you should be comfortable with the blinds being either open or closed, so if you open them at 45, they won't close again until the light intensity changes quite a bit - it has to go all the way up to 55. They will then stay closed until, once again, the light intensity's change will be significant, down to 45.

Final comment: you don't need the else statements after checking the sensor value. The motor is already set to 0, so there's nothing that needs to be done if the threshold hasn't been passed.

0

Okay, it took me some time to understand this because I am fairly new to programming but I see what you're getting at. This is definitely something to think about. You're saying having a threshold that is just like a thin line right? Thank you for adding this comment. I will have to try this out!

1

Do you not need a tolerance when opening and closing. I thought this was required to prevent feathering around a threshold. For water pumps the logic might be:

if WL > threshold:
    #turn on pump
else if WL < threshold - 0.2:
    #turn off pump

Once the pump has turned on, the water level needs to drop significantly in order to prevent the pump oscillating between on and off.

0

I never thought of feathering around the threshold. Thanks! I am fairly new to programming so these kinds of ideas are stepping into new learning grounds for me, thank you for that!

0

It may save a bit of wear on the motors, it might take a bit of tweaking to find a value that works for you. Other options to prevent it moving all the time could be to take an average over a number of measurements (e.g. 5 min) to ensure that the blinds don't move each time a cloud passes overhead. I'm sure like most programming things you will tweak it as you go and change the goal posts!

Enjoy

0

Oh damn yet another thought provoking idea. Thanks! I feel like nothing is perfect and every project can be tweaked if you think about it.

1
0

That's some surprisingly short and sweet code. I'd love to see a video of it in action.

0

I will try and find the video demonstrating the Robot in action.

2

I dusted off my old time capsule and managed to find the video demonstration of the Robot in action: http://www.gfycat.com/AdventurousGlisteningEuropeanfiresalamander The reason it closes when my finger is close to the sensor is because the red light from the light sensor reflects back into the sensor making a brighter reading.

0

Very interesting, I haven't come across Robot C before. What hardware is it running on?

1

Not OP, but I used it with Lego Mindstorms in a high school robotics course. Looks like it's also used on VEX and CORTEX.

0

The program is run on an NXT 1.0 Programmable Brick: https://shop.education.lego.com/legoed/en-US/catalog/product.jsp?productId=5003402&isSimpleSearch=false&ProductName=NXT+Base+Set&ProductLine=LEGO+MINDSTORMS+Education+NXT

I will try to find the video demonstration. I also used AutoDesk Inventor 3D to create a small frame and blinds that worked quite well with the lego: http://www.autodesk.com/products/inventor/overview

0

A cloudy day will cause problems for it though as it quickly turns off an on. You should have a minimum delay and/or another threshold.

1

In each function whether the blinds open or close I have a time delay: "wait1Msec (1000);" and on top of that I have another delay right before the variable "i" changes. This will prevent chaos, but maybe I should make the motors gradually increase in speed rather than jumping straight to the required speed.

0